/** Bhumika Udani     dt 08- Feb -2011      v1.2            Added user.isactive = true condition for the OptyList query
    Bhumika Udani     dt 14-March-2011      v1.3            Modified the update Oppty in TestOptySplits method, introduced new up/down condition calc    
    Arun Ramachandran dt 30-March-2012      v1.4            Reduced DML usage by adding collections.
    Bhumika Udani     dt 1-June-2012        v1.5            Fixed deploy error for custom validation 
*/
@isTest
private class TestApexIDCclasses{

/* test class for classes/triggers */
 
  static testMethod void testNumberOfReschedules() {
  List<Event> eventList = new List<Event>();
  List<Lead> eventLeadList = new List<Lead>();
  List<Account> eventAccountList = new List<Account>();
  List <User> userAccList = new List<user>();

  userAccList = [select id from user where (IsActive = true and profile.Name = 'SFA OOR Media Consultants') limit 2];
  ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Event', 'Local Advertiser Event');
  ID localAdvertiserAccountRecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
        
         Account testAcc = new Account();        
         testAcc.Name = 'UAPO test';         
         testAcc.Phone = '5674685675';         
         testAcc.ownerid = userAccList[0].id;         
         testAcc.recordTypeid = localAdvertiserAccountRecordTypeID; 
         
         Account testAcc1 = new Account();                           
         testAcc1.Name = 'AP test';         
         testAcc1.Phone = '3374685675';
         testAcc1.ownerid = userAccList[1].id;         
         testAcc1.recordTypeid = localAdvertiserAccountRecordTypeID;         
         
         eventAccountList.add(testAcc);         
         eventAccountList.add(testAcc1);
        
         insert eventAccountList;
         
         eventLeadList.add(CreateTestLead());
         eventLeadList.add(CreateTestLead());
         eventLeadList.add(CreateTestLead());

         //  eventAccountList = [select id from Account limit 3] ;

        Event e = new Event();
        e.RecordTypeId = localAdvertiserRecordTypeID;
        e.DurationInMinutes = 125;      
       // e.ActivityDateTime = Datetime.now()-1;
        e.Type = 'Appointment';
        e.StartDateTime = Datetime.now()-1;
        e.whoid = eventLeadList[0].id;
             
        Event e2 = new Event();
        e2.RecordTypeId = localAdvertiserRecordTypeID;
        e2.DurationInMinutes = 110; 
      //  e2.ActivityDateTime = Datetime.now()-3;  
        e2.Type = 'Appt - Follow-up';
        e2.StartDateTime = Datetime.now()-3;
        e2.whatid = eventAccountList[0].id;
        
        eventList.add(e);
        eventList.add(e2);
        //insert e2;
        insert eventList;
  
       eventList[0].DurationInMinutes =125;
       eventList[0].Appointment_type__c = 'Appt - Customer Care';
      // eventList[0].ActivityDateTime = Datetime.now();
       eventList[0].StartDateTime = Datetime.now();
       update  eventList;

   System.assertEquals(eventList[0].DurationInMinutes,125);
   System.assertEquals(eventList[0].Appointment_type__c,'Appt - Customer Care');

     }     
   
static testMethod void testOptySplits() {
    ID localAdvertiserRecordType1ID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals');
    ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Lead Order');
            
        List<Opportunity> OptyList = new list<Opportunity>();
        List<User> UserList = new List<User>();
        
        //UserList = [select id from user where IsActive = true limit 2];
       Profile p = [select id from profile where name='System Administrator'];           
       User u1 = new User(alias = 'Opt1', email='sysadminOpty@accenture.com',emailencodingkey='UTF-8', lastname='Test Opty 1', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testOppty11@testorg.com');
       User u2 = new User(alias = 'Opt2', email='sysadminOpty2@accenture.com',emailencodingkey='UTF-8', lastname='Test Opty 2', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testOppty21@testorg.com'); 
       UserList.add(u1);
       UserList.add(u2);
        //Insert u1;
        //Insert u2;
       insert UserList;
        
        
        
        date myDate = date.today();
        date newDate = mydate.addDays(2);
        
        Opportunity opty1 = new Opportunity(Name = 'TestOPpy1',CloseDate = myDate,Projected_Close_Date__c=newDate,Order_Date_SOLO__c=newDate, Opportunity_Type__c = 'Renew', Revenue_mo__c = 800,Monthly_Amount__c = 500,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c = u2.id,recordtypeid=localAdvertiserRecordType1ID ); 
        OptyList.add(opty1);         
        Opportunity opty2 = new Opportunity(Name = 'TestOPpy2',CloseDate = myDate, Projected_Close_Date__c=newDate,Revenue_mo__c = 0, Order_Date_SOLO__c = newDate, Opportunity_Type__c = 'Renew/Downgrade', Opportunity_Amount__c= 0,Monthly_Amount__c = 500,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c = u2.id,recordtypeid=localAdvertiserRecordTypeID ); 
         OptyList.add(opty2);
       Opportunity opty3 = new Opportunity(Name = 'TestOPpy3',CloseDate = myDate ,Projected_Close_Date__c=newDate,Revenue_mo__c = 90, Order_Date_SOLO__c = newDate,Opportunity_Type__c = 'Renew/Upgrade', Monthly_Amount__c = 0,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c =u2.id ,recordtypeid=localAdvertiserRecordType1ID ); 
         OptyList.add(opty3);         
        Opportunity opty4 = new Opportunity(Name = 'TestOPpy4',CloseDate = myDate ,Projected_Close_Date__c=newDate,Monthly_Amount__c = 55, Order_Date_SOLO__c = newDate,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c = u2.id, recordtypeid=localAdvertiserRecordType1ID ); 
         OptyList.add(opty4);         
        Opportunity opty5 = new Opportunity(Name = 'TestOPpy5',CloseDate = myDate ,Projected_Close_Date__c=newDate,Revenue_mo__c = 69, Order_Date_SOLO__c = newDate,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c = u2.id,recordtypeid=localAdvertiserRecordType1ID ); 
         OptyList.add(opty5);         
        Opportunity opty6 = new Opportunity(Name = 'TestOPpy6',CloseDate = myDate ,Projected_Close_Date__c=newDate, Order_Date_SOLO__c = newDate,StageName ='Signed Contract',ownerid =u1.id,Secondary_Owner__c = u2.id ,recordtypeid=localAdvertiserRecordTypeID ); 
         OptyList.add(opty6);        
        Opportunity opty7 = new Opportunity(Name = 'TestOppy2',CloseDate = myDate, Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate,Revenue_mo__c = 900,Monthly_Amount__c = 875,StageName ='Signed Contract',ownerid =u1.id); 
        OptyList.add(opty7);                 
        Opportunity opty8 = new Opportunity(Name = 'TestOPpy2',CloseDate = myDate,Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate,Revenue_mo__c = 0,Monthly_Amount__c = 500,StageName ='Signed Contract',ownerid=u1.id,recordtypeid=localAdvertiserRecordType1ID ); 
         OptyList.add(opty8);
        Opportunity opty9 = new Opportunity(Name = 'TestOPpy3',CloseDate = myDate,Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate,Revenue_mo__c = 90,Monthly_Amount__c = 0,StageName ='Signed Contract',ownerid=u1.id,recordtypeid=localAdvertiserRecordType1ID ); 
         OptyList.add(opty9);         
        Opportunity opty10 = new Opportunity(Name = 'TestOPpy4',CloseDate = myDate,Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate,StageName ='Signed Contract',ownerid =u1.id,recordtypeid=localAdvertiserRecordTypeID,Revenue_mo__c = 100,Monthly_Amount__c=10,SOLO_Contract_Revenue_mo__c=200,SOLO_Order_Value__c=100,SOLO_Prev_Monthly_Amt__c=100,SOLO_Prev_Order_Value__c=155 ); 
         OptyList.add(opty10);         
        Opportunity opty11 = new Opportunity(Name = 'TestOPpy5',CloseDate = myDate,Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate,StageName ='Signed Contract',ownerid =u1.id,recordtypeid=localAdvertiserRecordTypeID,Revenue_mo__c = 100,Monthly_Amount__c=10,SOLO_Contract_Revenue_mo__c=200,SOLO_Order_Value__c=100,SOLO_Prev_Monthly_Amt__c=100,SOLO_Prev_Order_Value__c=155 ); 
         OptyList.add(opty11);         
        Opportunity opty12 = new Opportunity(Name = 'TestOPpy6',CloseDate = myDate, Projected_Close_Date__c=newDate,Order_Date_SOLO__c = newDate, Opportunity_Type__c = 'Win-Back',Recurring_Charge__c =90, Opportunity_Amount__c=890,StageName ='Signed Contract',ownerid =u1.id,recordtypeid=localAdvertiserRecordType1ID,secondary_owner__c=u2.id,Revenue_mo__c = 100,Monthly_Amount__c=10,SOLO_Contract_Revenue_mo__c=200,SOLO_Order_Value__c=100,SOLO_Prev_Monthly_Amt__c=100,SOLO_Prev_Order_Value__c=155); 
         OptyList.add(opty12);  
         
        Notes__c Note1= new Notes__c (Ownerid = u2.id, Description__c = 'Dewsc12345'); 
        insert Note1;
        Insert OptyList;
        
        
       //OptyList.clear();
       List<Opportunity> OpptyToUpdate = new List<Opportunity>();
       List<Opportunity> Opptys= New List<Opportunity>();
        opty7.secondary_owner__c = u2.id;
        opty8.secondary_owner__c = u2.id;
        opty9.secondary_owner__c = u2.id;
        //opty10.secondary_owner__c = UserList[1].id;
        opty11.secondary_owner__c = u2.id;
        opty12.secondary_owner__c = u2.id;
        Note1.Ownerid = u1.id;            

        OpptyToUpdate.add(opty7);
        OpptyToUpdate.add(opty8);  
        OpptyToUpdate.add(opty9);  
        //OpptyToUpdate.add(opty10);  
        OpptyToUpdate.add(opty11); 
        OpptyToUpdate.add(opty12); 
        OpptyToUpdate.add(opty1); 
  
        update OpptyToUpdate;  
        update Note1;
  
       opty8.Revenue_mo__c = 2001;      
       //update Opty8;
       Opptys.add(Opty8);
       opty9.Monthly_Amount__c= 2333;
       Opty3.Monthly_Amount__c= 2333;
       
       //update Opty3;
       //update Opty9;
       Opptys.add(Opty3);
       Opptys.add(Opty9);
       opty2.secondary_owner__c = null;
       //update Opty2; 
       
       opty2.Recurring_Charge__c = 90;
       Opty7.Recurring_Charge__c = 50;
       
       //update opty2;  
       //update opty7;
       opty12.secondary_owner__c = NULL;
       opty12.Opportunity_Amount__c = 100;
       //update opty12; 
       Opptys.add(Opty2);
       Opptys.add(Opty7);
       Opptys.add(Opty12);
       Update Opptys;


          
    }



static testMethod void testUpdateAccountPrimaryOwner() {
 
         List<Account> accountList = new List<Account>();
         List<User> UserList = new List<User>();

         ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
                
         UserList = [select id from user where IsActive = true limit 2];
    
         Account testAcc = new Account();
         
         testAcc.Name = 'UAPO test';
         testAcc.Phone = '5674675675';
         testAcc.ownerid = UserList[0].id;
         testAcc.recordTypeid = localAdvertiserRecordTypeID;
         
         accountList.add(testAcc);
         
         insert accountList;
         
         accountList[0].ownerid = UserList[1].id;
         update accountList;
         }
 Static testMethod Void testAccountOORSecondaryOwnerUpdate(){
       Profile p = [select id from profile where name='System Administrator'];           
       List<User> userlist= New List<User>();
       //User u1 = new User(alias = 'Opt1', email='sysadminOpty@accenture.com',emailencodingkey='UTF-8', lastname='Test Opty 1', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testOppty1@testorg.com',SFA_Office__c='BLT');
       User u1 = new User(alias = 'Opt1', email='sysadminOpty@accenture.com',emailencodingkey='UTF-8', lastname='Test Opty 1',firstname='Test Opty 3', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testOppty3@testorg.com',SFA_Office__c='BLT');
       User u2 = new User(alias = 'Opt2',ManagerId=u1.Id, email='sysadminOpty2@accenture.com',emailencodingkey='UTF-8', lastname='Test Opty 2',firstname='Test Opty 4', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,timezonesidkey='Asia/Calcutta', username='testOppty4@testorg.com',SFA_Office__c='BOS'); 
       userlist.add(u1);
       userlist.add(u2);
       Insert userlist;
       List<Account> AccountList= New List<Account>();
       ID localAdvertiserRecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
       ID SFAOORRenewalecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals');
         Account acct = new Account();
         acct.Name='TestAccount';
         acct.Phone='919891824303';
         acct.OwnerId=userlist[0].Id;
         acct.RecordTypeId=localAdvertiserRecordTypeID; 
         acct.Secondary_Owner__c=userlist[0].Id;
         acct.Recurring_Charge__c=100.00;
         acct.Previous_AF_Assigned__c=0.00;
         acct.Last_Evergreen_Billed__c=300.00;
         acct.Last_Billed_Date__c=Date.ValueOf('2112-01-20'); 
         AccountList.add(acct);
         Insert AccountList;
         AccountList[0].Recurring_Charge__c=500.00;
         AccountList[0].OwnerId=userlist[1].Id;
         AccountList[0].Previous_AF_Assigned__c=100.00;
         AccountList[0].Last_Billed_Date__c=Date.ValueOf('2112-02-20');
         AccountList[0].Type__c='Evergreen';
         AccountList[0].Secondary_Owner__c=userlist[1].Id;
         AccountList[0].OOR_Secondary_Account_Owner__c=userlist[1].Id;
         //Update AccountList;
         AccountTeamMember AccMemb = new AccountTeamMember(); 
         AccMemb.AccountId = AccountList[0].id;   
         AccMemb.UserId = AccountList[0].Secondary_Owner__c;
         insert AccMemb;
         Opportunity Opp = New Opportunity(); 
         Opp.RecordTypeId = SFAOORRenewalecordTypeID;   
         Opp.Name = AccountList[0].Name;     
         Opp.AccountId = AccountList[0].Id;     
         Opp.OwnerId = AccountList[0].OwnerId;    
         Opp.Opportunity_Type__c = 'Bill Cycle Evergreen';  
         Opp.StageName = 'Completed'; 
         Opp.Probability = 1;    
         Opp.Revenue_mo__c = AccountList[0].Last_Evergreen_Billed__c;   
         Opp.CloseDate = AccountList[0].Last_Billed_Date__c;   
         Opp.SOLO_Order_State__c = 'C';   
         Opp.Order_Date_SOLO__c = AccountList[0].Last_Billed_Date__c;    
         Opp.SOLO_Contract_Date__c = AccountList[0].Last_Billed_Date__c;    
         Opp.Order_Completion_Date__c = AccountList[0].Last_Billed_Date__c;  
         Opp.Secondary_Owner__c=AccountList[0].OOR_Secondary_Account_Owner__c;   
         Opp.SOLO_Submitted_Date__c = AccountList[0].Last_Billed_Date__c;    
         Opp.Monthly_Amount__c = AccountList[0].Last_Evergreen_Billed__c;    
         Opp.SOLO_Contract_Revenue_mo__c = AccountList[0].Last_Evergreen_Billed__c; 
         Opp.SOLO_Prev_Monthly_Amt__c = 0;
                 
         Insert Opp;
         //OOR_CreateOppOnRecurringChange.CreateOrder(AccountList);
          }              
  
         
         static Lead CreateTestLead(){
            Lead l = new Lead();
            l.LastName = 'Unit Test';
            l.Company = 'UT Company';
            l.FirstName = 'DNC';

            insert l;
            return l;
         }
  Static testMethod Void OORUpdatesBookingDates()
  {
     ID localAdvertiserAccountRecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
     list<Account> acctList = new List <Account>();
     list<Contact> conList = new List <Contact>();
     list<Booking_Dates__c> bookList = new List <Booking_Dates__c>();
     list<Lead> leadList = new List <Lead>();

     Account testAcc = new Account();        
     testAcc.Name = 'OOR test';         
     testAcc.Phone = '5674685675';
     testAcc.Type__c= 'Win-Back';
     testAcc.Account_Status__c = 'Inactive';         
     //testAcc.ownerid = userAccList[0].id;         
     testAcc.recordTypeid = localAdvertiserAccountRecordTypeID;
     acctList.add(testAcc);
     //insert testAcc;
     Account testAcc2 = new Account();        
     testAcc2.Name = 'OOR test';         
     testAcc2.Phone = '5674685675';
     testAcc2.Type__c= 'Win-Back';
     testAcc2.Account_Status__c = 'Inactive';         
     //testAcc.ownerid = userAccList[0].id;         
     testAcc2.recordTypeid = localAdvertiserAccountRecordTypeID;
     //insert testAcc2;
     acctList.add(testAcc2);

     Contact testCont = new Contact();
     testCont.firstname = 'ABC';
     testCont.lastname = 'last';
     testCont.phone = '9292929292';
     testCont.AccountId = testAcc.Id;
     testCont.RecordtypeId = RecordTypeHelper.GetRecordTypeID('Contact', 'Local Advertiser');
     conList.add(testCont);
     //insert testCont;
     Account testAcc1 = new Account();        
     testAcc1.Name = 'OORLeadData';         
     testAcc1.Phone = '5674685675';
     testAcc1.recordTypeid = localAdvertiserAccountRecordTypeID;
     acctList.add(testAcc1);
     //insert testAcc1;
     insert acctList;
     insert conList;
    
     date myDate = date.today();
     Booking_Dates__c booking= New Booking_Dates__c ();
     booking.Booking_Closing_Month__c='6';
     booking.Booking_Closing_Year1__c='2111';
     booking.Booking_Closing_Date__c=Date.ValueOf('2111-06-20');
     //Insert booking;
     bookList.add(booking);
     Booking_Dates__c booking1= New Booking_Dates__c ();
     booking1.Booking_Closing_Month__c='7';
     booking1.Booking_Closing_Year1__c='2111';
     booking1.Booking_Closing_Date__c=Date.ValueOf('2111-07-20');
     bookList.add(booking1);
     //Insert booking1;
     Booking_Dates__c booking3= New Booking_Dates__c ();
     booking3.Booking_Closing_Month__c='12';
     booking3.Booking_Closing_Year1__c='2111';
     booking3.Booking_Closing_Date__c=Date.ValueOf('2111-12-20');
     //Insert booking3;
     bookList.add(booking3);
     Booking_Dates__c booking2= New Booking_Dates__c ();
     booking2.Booking_Closing_Month__c='1';
     booking2.Booking_Closing_Year1__c='2112';
     booking2.Booking_Closing_Date__c=Date.ValueOf('2112-01-20');
     //Insert booking2;
     bookList.add(booking2);
     
     Opportunity oppty= New Opportunity();
     oppty.Name='TestOppty';
     //oppty.AccountId = testAcc.Id;
     oppty.StageName ='Signed Contract';
     oppty.CloseDate= myDate;
     oppty.SOLO_Submitted_Date__c=Date.ValueOf('2111-06-05');
     oppty.Order_Completion_Date__c=Date.ValueOf('2111-07-10');
     oppty.RecordtypeId = RecordTypeHelper.GetRecordTypeID('Opportunity', 'SFA-OOR Renewals');
     Insert oppty;
     oppty.Booking_Closing_Date__c=booking1.Booking_Closing_Date__c;
     oppty.Booked_Date__c=Date.ValueOf('2111-07-31');
     oppty.SOLO_Submitted_Date__c=Date.ValueOf('2111-12-06');
     oppty.Order_Completion_Date__c=Date.ValueOf('2111-12-22');
     Update oppty;
     Id LeadRecId = RecordTypeHelper.GetRecordTypeID('Lead', 'Local Advertiser');

     Lead lead1 = new Lead();
     lead1.LastName = 'Test';
     lead1.Company = 'OORLeadData';
     lead1.FirstName = 'OOR';
     lead1.phone = '9292929291';
     lead1.Win_Back_Account__c = testAcc.Id;
     lead1.Win_Back_Lead__c = TRUE;
     lead1.RecordtypeId = LeadRecId;
     lead1.Unique_lead_list__c = '1234';
     //insert lead1;
     leadList.add(lead1);
     Lead lead2 = new Lead();
     lead2.LastName = 'Test';
     lead2.Company = 'OORLeadData';
     lead2.FirstName = 'OOR';
     lead2.phone = '9292929291';
     lead2.RecordtypeId = LeadRecId;
     lead2.Unique_lead_list__c = '1234';
     lead1.Win_Back_Account__c = testAcc2.Id;
     lead1.Win_Back_Lead__c = TRUE;
     //insert lead2;
     leadList.add(lead2);
     insert(leadList);
     ApexPages.StandardController thecontroller = new ApexPages.StandardController(lead2);
     OORDuplicateLeadChecklistctrl controllerLead = new OORDuplicateLeadChecklistctrl(thecontroller);
     OORDuplicateAccChecklistCtrl  controllerAccount = new OORDuplicateAccChecklistCtrl(thecontroller);
       }
     static testMethod void myTest7() { 
     list<Booking_Dates__c> bkList = new List <Booking_Dates__c>();
          Booking_Dates__c booking = New Booking_Dates__c(); 
          booking.Booking_Closing_Month__c='3';  
          booking.Booking_Closing_Year1__c='2111';  
          booking.Booking_Closing_Date__c=Date.ValueOf('2111-4-17');  
         //Insert booking ;    
         bkList.add(booking);
            Booking_Dates__c booking1 = New Booking_Dates__c();   
            booking1.Booking_Closing_Month__c='4';   
            booking1.Booking_Closing_Year1__c='2111';   
            booking1.Booking_Closing_Date__c=Date.ValueOf('2111-5-17');  
            if(booking1.Booking_Closing_Month__c!= booking.Booking_Closing_Month__c && booking1.Booking_Closing_Year1__c!=booking.Booking_Closing_Year1__c){
                //Insert booking1 ; 
                bkList.add(booking);
                insert bkList;
   }  }
   static testMethod void testOrderCreateonDigitalExpress() {
   ID localAdvertiserAccountRecordTypeID = RecordTypeHelper.GetRecordTypeID('Account', 'Local OOR Customer');
       Account acc = new Account();
       acc.name = 'OOR Digital Express';
       acc.phone = '9329921932';
       acc.recordtypeid = localAdvertiserAccountRecordTypeID;
       insert acc;
      Digital_Express__c DEList = new Digital_Express__c();
      DEList.Company_Name__c = 'newCompany';
      DEList.Completed_Date__c = Date.ValueOf('2012-4-17');
      DEList.Owner_Rep_Name__c = UserInfo.getUserId();
      DEList.Monthly_Amount__c = 100;
      DEList.Office_Code__c = 'BLT';
      DEList.Total_Amount__c = 200;
  Insert DEList;
  }
  static testmethod void testOORPreventDuplicateAssignmentGroup(){
  list<Assignment_Group_Name__c> AsstGName = new List<Assignment_Group_Name__c >();
  Assignment_Group_Name__c AGName=New Assignment_Group_Name__c();
  AGName.Name='Assignment Group Test';
  AGName.Type__c='Lead';
  AGName.Round_Robin__c=True;
  AGName.Office_Code__c='AGT';
  //Insert AGName;
  AsstGName.add(AGName);
  Assignment_Group_Name__c AGName1=New Assignment_Group_Name__c();
  AGName1.Name='Assignment Group Test1';
  AGName1.Type__c='Lead';
  AGName1.Round_Robin__c=True;
  AGName1.Office_Code__c='AGT1';
  if(AGName1.Name!=AGName.Name){
  //Insert AGName1;
  AsstGName.add(AGName1);
  insert AsstGName;
  } 
  }
  
  static testmethod void testOORTelesalesAssociateCampaignOnLead()
  {
   
   Campaign campNew = New Campaign();
   campNew.Name='testOORTelesalesCampaigg';
   campNew.isActive=True;
   campNew.StartDate=Date.Today();
   campNew.EndDate=Date.Today();
   Insert campNew;
  
   Lead leadNew = New Lead();
   leadNew.FirstName='testFirstLead';
   leadNew.LastName='testLastName';
   leadNew.Company='testCompany';
   leadNew.Phone='89799797989';
   LeadNew.LeadSource = 'Dialer';
   Insert leadNew;
  
   CampaignMember campMembNew= New CampaignMember();
   campMembNew.CampaignId=campNew.Id;
   campMembNew.LeadId=leadNew.Id;
   insert campMembNew;
   
   Test.startTest();
   leadNew.OORTelesalesCampaign__c=campMembNew.CampaignId;
   Update leadNew; 
   Test.stopTest();
   }             
}